<?php

include_once "ElementItem.php";
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ComboBoxTag
 *
 * @author Jhonny
 */
class ComboBoxTag {
    private $name;
    private $values;
    public function __construct() {
        $this->values = array();
    }
    public function getValues() {
        return $this->values;
    }

    public function addElementItem(ElementItem $item){
        array_push($this->values, $item);
    }
    public function addElementItemValues($id,$value,$selected){
        $item = new ElementItem();
        $item->setId($id);
        $item->setValue($value);
        $item->setSelected($selected);
        $this->addElementItem($item);
    }
    public function setValues($values) {
        $this->values = $values;
    }

    public function getName() {
        return $this->name;
    }

    public function setName($name) {
        $this->name = $name;
    }

    public function toString(){
        $value='';
        $value.='<select name="'.$this->getName().'" >';
        if($this->getValues()!=null){
            foreach ($this->getValues() as $item) {
                $value.='<option value="'.$item->getId().'"';
                if($item->getSelected()!=null&& 
                   $item->getSelected()==true){
                    $value.=' selected="true" ';
                }
                $value.='>'.$item->getValue().'</option>';
            }
        }
        $value.='</select>';
        return $value;
    }
}
?>
